 #ifndef User_define_H
#define User_define_H

#include "DSP280x_Device.h"


#define PI (4 * atan(1.0))
#define NUMBER_OF_FACTOR (4)
//#define WLPF (500.0)
//#define WLPF (400.0)
#define WLPF (30.0)
//#define WLPF (100.0)
//#define DT_CONTROL (0.1)
#define STEP (1.0e-4)
//#define STEP (0.01)
//#define OMEGA_CUT_OFF (0.6)
#define NUMBER_OF_OUTPUT_S (4)
#define G (9.80621)
#define R (0.18)
#define K1 (40)
#define K2 (40)

//const double PI  = 3.1415926535897932385;
//const double sqrt2 =  1.4142135623730950488;

/*#define FS1 (140)
#define FS2 (365)
#define FS3 (366.6)
#define FS4 (142.6)
*//*
#define FS1 (210)
#define FS2 (393.5)
#define FS3 (380.8)
#define FS4 (142.7)
*//*
#define FS1 (459.2)
#define FS2 (792.88)
#define FS3 (565.64)
#define FS4 (144)
*/
//#define FS1 (81)
//#define FS2 (108)
//#define FS3 (54)
//#define FS4 (12)

  #define FS1 (459.2)
  #define FS2 (792.88)
  #define FS3 (565.64)
  #define FS4 (144)

 // #define FS1 (98.45600625)
  //#define FS2 (125.0235)
  //#define FS3 (59.535)
  //#define FS4 (12.6)


/*-140,-1,-0.3-0.4j,-0.3+0.4j*/

/*tattuya*//*
#define FL1 (44.4)
#define FL2 (205.3)
#define FL3 (298.57)
#define FL4 (153.12)
*//*OK*//*
#define FL1 (54.7)
#define FL2 (242.57)
#define FL3 (371.1)
#define FL4 (192.8)
*/
/*no.1*//*
#define FL1 (53.7)
#define FL2 (191.8)
#define FL3 (338.025)
#define FL4 (276.25)
*//*no.2*//*
#define FL1 (43.7)
#define FL2 (242.36)
#define FL3 (371.842)
#define FL4 (192.1)
*//*no.3*//*
#define FL1 (44.1)
#define FL2 (173.06)
#define FL3 (390.6)
#define FL4 (369.22)
*//*no.4*//*
#define FL1 (44.1)
#define FL2 (178)
#define FL3 (598.54)
#define FL4 (709)
*//*no.5*//*
#define FL1 (34.2)
#define FL2 (137)
#define FL3 (453.2)
#define FL4 (532)
*//*
#define FL1 (65)
#define FL2 (312.5)
#define FL3 (750)
*//*
#define FL1 (63)
#define FL2 (182.26)
#define FL3 (135.6)
*//*
#define FL1 (65)
#define FL2 (306)
#define FL3 (375)
*//*
#define FL1 (65)
#define FL2 (308.5)
#define FL3 (510)
*/
/*
#define FL1 (65)
#define FL2 (326.5)
#define FL3 (1590)
*/
/*
#define FL1 (65)
#define FL2 (306.5)
#define FL3 (375)
*/
/*
#define FL1 (150.0)
#define FL2 (100.0)
#define FL3 (80.0)
*/
//#define FL1 (27)
//#define FL2 (27)
//#define FL3 (9)
/*OKOKOK!!!!*/
   #define FL1 (220)
   #define FL2 (230)
   #define FL3 (45)
/*
#define FL1 (104)
#define FL2 (405)
#define FL3 (500)
*/
/*
#define FL1 (21)
#define FL2 (520)
#define FL3 (500)
*/
/*
#define FL1 (170)
#define FL2 (17.05)
#define FL3 (85)
*//*
#define FL1 (242.57)
#define FL2 (371.1)
#define FL3 (192.8)
*/
/*
#define FL1 (150)
#define FL2 (105)
#define FL3 (85)
*//*
#define FL1 (14)
#define FL2 (44.25)
#define FL3 (42.5)
*//*
#define FL1 (17)
#define FL2 (31.01)
#define FL3 (15.15)
*/
//#define Ms2 13.2
//#define lcs2 0.35
//#define Ms1 0.5

#define MS1 0.5
#define MS2 13.5
#define LCS2 0.51333
#define IS2 1.22

#define WCS  3.15
//#define Icc 0.081
//#define I2 0.25
//#define Jla1 2.4
//#define Jla2 0.025
//#define lla 0.5
//#define MLa 13.5
//#define Ml2 5
//#define Ll1 0.57  
//#define lcl2 0.17  
//#define Il2 0.258
#define ML 13.5
#define JLA1 3.0
#define JLA2 0.02
#define LR 0.5
#define WC 3 
//Acceleration sensor parameters(CXL10GP3)

#define ACC_SENSITIVITY 0.2
#define VOLTGEZERO_X_AXIS 1.240
#define VOLTGEZERO_Y_AXIS 1.215
#define VOLTGEZERO_Z_AXIS 1.277
/*
#define VOLTGEZERO_X_AXIS 1.25
#define VOLTGEZERO_Y_AXIS 1.25
#define VOLTGEZERO_Z_AXIS 1.25
*/
// Jairo parameters(CR03-04)
#define SCALE_FACTOR 0.01
#define VDD 5.0
#define MAX_AD_VOLTAGE 3.0
//#define JAIRO_OFFSET (VDD / 2)
//#define AD_OPEAMP_GAIN 0.5

// ADC start parameters
#define ADC_MODCLK 0x1  // HISPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*15)         = 3.33MHz
#define ADC_CKPS   0x1   // ADC module clock = HSPCLK/2*ADC_CKPS   = 12,5MHz/(15*2) = 11.1KHz
#define ADC_SHCLK  0x1   // S/H width in ADC module periods                      = 16 ADC clocks
#define AVG        10  // Average sample limit
#define ZOFFSET    0x22  // Average Zero offset
#define BUF_SIZE   128  // Sample buffer size

#define RESIST1    330
#define RESIST2    1000
#define Vl        1.5
#define Vs        1.5
#define Taus      28.65
#define Taul      31.85
#define OFFSET1    1.4
//#define LIMITl     63.5
//#define LIMITs     25//95.5

#define TIME_OUTPUT 10.0
#define TIME_CAL    TIME_OUTPUT/256
#define ADC_SCALE   4095
#define ENCORDER_SCALE 8192
#define OFFSET2     1.2
//#define OFFSET2     1.4
#define ERROR       0.2

//#define ERROR       0.0
#define RADIUS      0.2

#define POINT    500

//---------------------------------------------------------------------------
// Include Standard C Language Header Files
//
#include <string.h>


//---------------------------------------------------------------------------
// Include any other Header Files
//
#include "DSP280x_DefaultIsr.h"			// ISR definitions (for non-BIOS projects only)
#include "Dac.h"						// ePWM DAC driver
#include "SFO.h"						// HRPWM scale factor optimization
#include "Example_posspeed.h"

//---------------------------------------------------------------------------
extern float32 us;
extern float32 ul;
extern Uint16 DAC1_frac;
extern Uint16 DAC2_frac;

//For output in file
//extern int xhs0[POINT];
//extern int xhs1[POINT];
//extern int xhs2[POINT];
//extern int data_u[POINT];
//For cast
//extern int tmp_u;
//extern int tmp_0;
//extern int tmp_1;
//extern int tmp_2;

//extern double theta_3_dot;
//extern int theta_3_dot;
//extern int counter; 
//extern double xs[NUMBER_OF_FACTOR];
//extern double ys[NUMBER_OF_OUTPUT_S];
  
extern POSSPEED theta_2;//=POSSPEED_DEFAULTS;
extern POSSPEED phi;//=POSSPEED_DEFAULTS;

extern int roll;
extern int roll_l;
extern int firstSample;
#define deltaT 0.005;
#define wGyro			10.0f


//IMU
//Macro
typedef unsigned char byte;  //8-bit
typedef unsigned int  word;  //16bit
typedef unsigned long dword; //32-bit

extern unsigned long timer0_millis;

enum {false, true} bool;
enum bool {no, yes};

#endif // end of User_define_H definition

/*** end of file *****************************************************/
